import requestInstance from '@/utils/request'
/**
 * 获取案例列表
 * @param {Object} params - 查询参数
 * @returns {Promise} 案例列表
 */
export const getCaseList = async (params = {}) => {
  try {
    const response = await requestInstance.get('case/list', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取案例列表失败:', error);
    throw error;
  }
};

/**
 * 获取案例详情
 * @param {string|number} id - 案例ID
 * @returns {Promise} 案例详情
 */
export const getCaseDetail = async (id) => {
  try {
    const response = await requestInstance.get(`/api/case/detail/${id}`);
    return response.data;
  } catch (error) {
    console.error('获取案例详情失败:', error);
    throw error;
  }
};

/**
 * 添加案例
 * @param {Object} caseData - 案例数据
 * @returns {Promise} 添加结果
 */
export const addCase = async (caseData) => {
  try {
    const response = await requestInstance.post('case/add', caseData);
    return response.data;
  } catch (error) {
    console.error('添加案例失败:', error);
    throw error;
  }
};

/**
 * 编辑案例
 * @param {string|number} id - 案例ID
 * @param {Object} caseData - 案例数据
 * @returns {Promise} 编辑结果
 */
export const updateCase = async (id, caseData) => {
  try {
    const response = await requestInstance.put(`/api/case/update/${id}`, caseData);
    return response.data;
  } catch (error) {
    console.error('编辑案例失败:', error);
    throw error;
  }
};

/**
 * 删除案例
 * @param {string|number} id - 案例ID
 * @returns {Promise} 删除结果
 */
export const deleteCase = async (id) => {
  try {
    const response = await requestInstance.delete(`/api/case/delete/${id}`);
    return response.data;
  } catch (error) {
    console.error('删除案例失败:', error);
    throw error;
  }
};

/**
 * 批量删除案例
 * @param {Array} ids - 案例ID数组
 * @returns {Promise} 删除结果
 */
export const batchDeleteCases = async (ids) => {
  try {
    const response = await requestInstance.post('case/batch-delete', {
      ids
    });
    return response.data;
  } catch (error) {
    console.error('批量删除案例失败:', error);
    throw error;
  }
};